package com.buildings.view;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.buildings.R;
import com.buildings.activity.table.CraterActivity;
import com.buildings.activity.table.DrillHoleActivity;
import com.buildings.activity.table.FaultSvyPointActivity;
import com.buildings.activity.table.GeoGeomorphySvyPointActivity;
import com.buildings.activity.table.GeochemicalSvyLineActivity;
import com.buildings.activity.table.GeochemicalSvyPointActivity;
import com.buildings.activity.table.GeologicalSvyLineActivity;
import com.buildings.activity.table.GeologicalSvyPlanningLineActivity;
import com.buildings.activity.table.GeologicalSvyPlanningPtActivity;
import com.buildings.activity.table.GeologicalSvyPointActivity;
import com.buildings.activity.table.GeomorStationActivity;
import com.buildings.activity.table.GeomorphySvyLineActivity;
import com.buildings.activity.table.GeomorphySvyPointActivity;
import com.buildings.activity.table.GeomorphySvyReProfActivity;
import com.buildings.activity.table.GeomorphySvyRegionActivity;
import com.buildings.activity.table.GeomorphySvySamplePointActivity;
import com.buildings.activity.table.GeophySvyLineActivity;
import com.buildings.activity.table.GeophySvyPointActivity;
import com.buildings.activity.table.LavaActivity;
import com.buildings.activity.table.SamplePointActivity;
import com.buildings.activity.table.StratigraphySvyPointActivity;
import com.buildings.activity.table.TanCaodianActivity;
import com.buildings.activity.table.VolcanicSamplePointActivity;
import com.buildings.activity.table.VolcanicSvyPointActivity;
import com.buildings.adapter.SelectType2Adapter;
import com.buildings.adapter.SelectTypeAdapter;
import com.buildings.bean.TableTypeListBean;
import com.buildings.event.EventCode;
import com.buildings.event.MessageEvent;
import com.buildings.event.MessageEventEntity;
import com.buildings.util.DataUtils;
import com.google.gson.Gson;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class SelectMapLayerFragmentDialog extends DialogFragment implements View.OnClickListener {

    View mView;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, R.style.custom_dialog);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        super.onActivityCreated(savedInstanceState);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0x00000000));
        getDialog().getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.dialog_select_map_layer, container, false);
        Window window = getDialog().getWindow();
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        WindowManager.LayoutParams params = window.getAttributes();
        params.gravity = Gravity.TOP;
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);
        initView();
        return mView;
    }

    private RelativeLayout rlMap1, rlMap2;
    private ImageView ivMap1, ivMap2;

    public void initView() {
        rlMap1 = mView.findViewById(R.id.rl_map1);
        rlMap2 = mView.findViewById(R.id.rl_map2);
        ivMap1 = mView.findViewById(R.id.iv_map1);
        ivMap2 = mView.findViewById(R.id.iv_map2);
        rlMap1.setOnClickListener(this);
        rlMap2.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_map1:
                selectMap(1);
                EventBus.getDefault().post(new MessageEventEntity(EventCode.SELECT_MAP_LAYER2));
                dismiss();
                break;
            case R.id.rl_map2:
                selectMap(2);
                EventBus.getDefault().post(new MessageEventEntity(EventCode.SELECT_MAP_LAYER1));
                dismiss();
                break;
        }
    }

    public void selectMap(int select){
        ivMap1.setImageResource(R.mipmap.select_false);
        ivMap2.setImageResource(R.mipmap.select_false);
        switch (select){
            case 1:
                ivMap1.setImageResource(R.mipmap.select_true);
                break;
            case 2:
                ivMap2.setImageResource(R.mipmap.select_true);
                break;
        }
    }

    public static SelectMapLayerFragmentDialog newInstance() {
        SelectMapLayerFragmentDialog fragmentB = new SelectMapLayerFragmentDialog();
        Bundle bundle = new Bundle();
        fragmentB.setArguments(bundle);
        return fragmentB;
    }


}
